package com.haodf.skeleton

import android.graphics.Color
import android.util.Log
import android.view.View
import android.widget.TextView
import androidx.core.graphics.ColorUtils


/**
 *@author xiaxiao
 *@date 2023/5/5.
 *
 */
class SkUtil {
    companion object {
        fun createNewColor(color1: Int?): Int? {
            color1 ?: return null
            val alpha = Color.alpha(color1)
            return ColorUtils.blendARGB(color1, Color.WHITE, 0.5f)
//            val color2 = Color.WHITE
//            val r = Color.red(color1)
//            val g = Color.green(color1)
//            val b = Color.blue(color1)
//
//            val ovR = Color.red(color2)
//            val ovG = Color.green(color2)
//            val ovB = Color.blue(color2)
//
//            val alpha = Color.alpha(color1)
//            val newR = createColor(r, ovR, alpha);
//            val newG = createColor(g, ovG, alpha);
//            val newB = createColor(b, ovB, alpha);
//
//            return Color.rgb(newR, newG, newB);
        }


        fun createColor(color: Int?): Int? {
            color ?: return null
            val r = Color.red(color)
            val g = Color.green(color)
            val b = Color.blue(color)
            return Color.argb(10, r, g, b)
        }

        fun log(s: String? = null, i: Int? = null) {
            Log.i("xiaxiao", "$s $i")
        }

        fun debugView(view: View?) {
            view ?: return
            if (!SkeletonLayout.DEBUG) {
                return
            }
            val id = try {
                view.context.resources.getResourceEntryName(view.id)
            } catch (e: Exception) {
                "NOID"
            }
            val text = if (view is TextView) {
                view.text
            } else {
                ""
            }
            val clazzName = view.javaClass.name
            val loc = IntArray(2)
            view.getLocationOnScreen(loc)
            Log.i(
                "SkeletonFrameWork",
                "View:[class = $clazzName, id = $id, text = $text, location=[${loc[0]}, ${loc[1]}]]"
            )
        }
    }


}